# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=lsp-server
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=1.2.4
pkgrel=1
pkgdesc='Python Language Server for the Language Server Protocol (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('MIT')
url='https://github.com/python-lsp/python-lsp-server'
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-jedi
    ${MINGW_PACKAGE_PREFIX}-python-jsonrpc-server
    ${MINGW_PACKAGE_PREFIX}-python-lsp-jsonrpc
    ${MINGW_PACKAGE_PREFIX}-python-pluggy
    ${MINGW_PACKAGE_PREFIX}-python-ujson
)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-setuptools)
optdepends=(
    "${MINGW_PACKAGE_PREFIX}-python-rope: for Completions and renaming"
    "${MINGW_PACKAGE_PREFIX}-python-pyflakes: linter to detect various errors"
    "${MINGW_PACKAGE_PREFIX}-python-mccabe: linter for complexity checking"
    "${MINGW_PACKAGE_PREFIX}-python-pydocstyle: linter for docstring style checking"
    "${MINGW_PACKAGE_PREFIX}-python-pycodestyle: linter for style checking"
    "${MINGW_PACKAGE_PREFIX}-python-autopep8: for code formatting"
    "${MINGW_PACKAGE_PREFIX}-python-yapf: for code formatting"
)
source=(https://github.com/python-lsp/python-${_realname}/archive/v${pkgver}.tar.gz)
sha256sums=('3e9102808f661df18a54e2ddd97285d4b3c4cbc0af6fed8439a1960617f74674')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "python-${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
